from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.api import mail
import sys
import feedparser



class Post(db.Model):
	url = db.StringProperty()
	titulo = db.StringProperty()
	cuerpo = db.StringProperty()
	feed = db.ReferenceProperty(Feed)
	enviado = db.StringProperty()
	

class MainPage(webapp.RequestHandler):
  def get(self):
	
	self.response.out.write("""
      <html>
	  <head>
	  <title>ReaderToMail - Google Reader in your mail</title>
	  <link rel="icon" type="image/png" href="img/favicon.ico">
	  </head>
        <body>
          No deberias estar por aqui.
        """)
		
	feeds = Feed.all()
	
	for f in feeds:
		d = feedparser.parse(f)
		self.response.out.write("""</br>""")
		for i in d:
			self.response.out.write(i.title)
		
		#obtener los post
		#ver si no estan ya duplicados
		#eliminar duplicaods
		#put
	
	# for de los post, donde enviado sea false
	
	mail = self.request.get("correo")
	
	self.response.out.write(mail)
	self.response.out.write("""</body>
      </html>""")
	  

	  
	  
application = webapp.WSGIApplication(
                                     [('/', MainPage)], 
                                     debug=True)


def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()